<template>
  <div>
    <!-- 搜索 -->
    <!-- 整车保修期查询 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams"  :fetchapi="fetchapi" :datakey="'records'"  :onColumnsChange="columns => (this.columns = columns)" :is-select-column="false">
      <template slot="controls" slot-scope="props">
        <multiuse-button type="primary" :click="exportFileBtn.bind()">下载</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="'车型'" width="850px" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <vehicle @close="close" @save="save"></vehicle>
    </BaseDialog>
  </div>
</template>
<script>
import { exportExcelFile } from '@/utils/index';
import vehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
import { dictionary } from '@/utils/dictMixin';
import { getListByPage,getListForExport, newSave, piliangqiyong, piliangtingyong, excelExport, editSave,exporturl } from '@/api/claim/dealer/FullCarWarrantyQuery';
export default {
   mixins: [dictionary],
  components: {
    vehicle
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: true,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi: getListByPage,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '选择车辆',
      visibleAdd: false
    };
  },

  methods: {
    // 导出
   async exportFileBtn() {
      // let json = Object.assign({}, { CODE: 'CODE_00000187' }, this.fetchParams);
      // let res = await exporturl(json);
      // if (res.resultCode == 200) {
      //   this.$router.push('/admin/auth/oem/downloadCenter');
      // }
      this.loading1 = true;
      getListForExport(this.fetchParams).then(res => {
        exportExcelFile(res.data, '整车保修期');
      });
      this.loading1 = false;
    },
    save(obj) {
      this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
      this.visible = false;
    },
    close() {
      this.visible = false;
    },
    chooseOrderNo() {
      this.visible = true;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'modelName',
          placeholder: '请选择车系...',
          initialValue: '',
          filterable: true,
          itemList: []
        },
        {
          type: 'SELECT', 
          label: '营运类型', 
          fieldName: 'vpType', 
          placeholder: '请选择营运类型...', 
          initialValue: '', 
          itemList: [
            { text: '运营', value: 55841001 },
            { text: '非运营', value: 55841002 }
            ], 
          filterable: true,
        },
        {
          type: 'INPUT',
          label: '保修期',
          fieldName: 'vpPeriod',
          initialValue: '',
          placeholder: '请输入保修期...',
          rules: [
            {
              validator: (rule, value, callback) => {
                if (value) {
                  if (Number.isInteger(Number(value))) {
                    callback();
                  } else {
                    callback(new Error('请输入数字值'));
                  }
                } else {
                  callback();
                }
              },
              trigger: ['blur', 'change'],
            },
          ],
          unitRender: () => {
            return <span>(月)</span>;
          },
        },
        {
          type: 'INPUT',
          label: '保修里程',
          fieldName: 'vpMile',
          initialValue: '',
          placeholder: '请输入保修里程...',
          rules: [
            {
              validator: (rule, value, callback) => {
                if (value) {
                  if (Number.isInteger(Number(value))) {
                    callback();
                  } else {
                    callback(new Error('请输入数字值'));
                  }
                } else {
                  callback();
                }
              },
              trigger: ['blur', 'change'],
            },
          ],
          unitRender: () => {
            return <span>(KM)</span>;
          },
        },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '状态', dataIndex: 'statusStr', sorter: true},
        {title: '车系', dataIndex: 'modelName', sorter: true},
        {title: '营运类型', dataIndex: 'typeName', sorter: true},
        {title: '保修期（月）', dataIndex: 'vpPeriod', sorter: true},
        {title: '保修里程（KM）', dataIndex: 'vpMile', sorter: true},
        {title: '创建人', dataIndex: 'createdBy', sorter: true},
        {title: '创建时间', dataIndex: 'createdAt', sorter: true},
        {title: '修改人', dataIndex: 'updatedBy', sorter: true},
        {title: '修改时间', dataIndex: 'updatedAt', sorter: true}

      ];
    }
  }

};
</script>

<style lang="less" scoped></style>
